package com.teacher.game.framework.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * 简化版难度偏好管理器
 * 用于保存和恢复用户的难度选择
 */
public class DifficultyPreferenceManager {
    
    private static final String PREFS_NAME = "DifficultyPrefs";
    private static final String KEY_SELECTED_DIFFICULTY = "selected_difficulty";
    private static final int DEFAULT_DIFFICULTY = 1; // 默认普通难度
    
    private SharedPreferences prefs;
    private Context context;
    
    public DifficultyPreferenceManager(Context context) {
        this.context = context;
        this.prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    }
    
    /**
     * 保存选中的难度
     * @param difficulty 难度级别 (0=简单, 1=普通, 2=困难)
     */
    public void setSelectedDifficulty(int difficulty) {
        prefs.edit()
            .putInt(KEY_SELECTED_DIFFICULTY, difficulty)
            .apply();
        Log.d("DifficultyPrefs", "保存难度设置: " + difficulty);
    }
    
    /**
     * 获取选中的难度
     * @return 难度级别
     */
    public int getSelectedDifficulty() {
        int difficulty = prefs.getInt(KEY_SELECTED_DIFFICULTY, DEFAULT_DIFFICULTY);
        Log.d("DifficultyPrefs", "读取难度设置: " + difficulty);
        return difficulty;
    }
    
    /**
     * 重置为默认难度
     */
    public void resetToDefault() {
        setSelectedDifficulty(DEFAULT_DIFFICULTY);
    }
}